package com.ftg.midamall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ftg.midamall.comm.vo.CodeStatusEnum;
import com.ftg.midamall.comm.vo.RespMessUtil;
import com.ftg.midamall.entity.PmsBrand;
import com.ftg.midamall.service.impl.PmsBrandServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import jdk.internal.org.objectweb.asm.tree.analysis.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author qjw
 * @since 2023-11-02
 */
@RestController
@Api(tags = "商品品牌模块")
@RequestMapping("/pms/pmsBrand")
public class PmsBrandController {

    @Resource
    PmsBrandServiceImpl brandService;

    @GetMapping("/showAllWithPage")
    @ApiOperation("管理员查看商品品牌信息")
    public RespMessUtil<IPage> showGoods(
            @ApiParam(value = "页码", name = "pageSize", required = true) @RequestParam(value = "pageSize", defaultValue = "1") Long pageSize,
            @ApiParam(value = "显示条数", name = "pageLimit", required = true) @RequestParam(value = "pageLimit", defaultValue = "10") Long pageLimit,
            @ApiParam(value = "商品名称", name = "name") @RequestParam(value = "name", required = false) String name

    ){
        return brandService.showAllWithPage(pageSize,pageLimit,name);
    }

    @PostMapping("/saveBrand")
    @ApiOperation("管理员添加商品品牌")
    public RespMessUtil<Integer> insertBrand(@RequestBody PmsBrand brand){

        int i = brandService.insertBrand(brand);
        return i>0 ? RespMessUtil.build(CodeStatusEnum.SUCCESS,i):RespMessUtil.insertFailure();
    }

    @DeleteMapping("/deleteBrand/{id}")
    @ApiOperation("管理员删除品牌")
    public RespMessUtil<Integer> deleteBrand(@ApiParam(name = "id",value = "主键",required = true) @PathVariable("id")Long id){
        Integer dele = brandService.deleById(id);
        return dele>0?RespMessUtil.build(CodeStatusEnum.SUCCESS,dele):RespMessUtil.deleteFailure();
    }

    @PutMapping("/updateBrand")
    @ApiOperation("管理员修改品牌")
    public RespMessUtil<Integer> updateBrand(@RequestBody PmsBrand brand){
        int i = brandService.updateBrand(brand, brand.getId());
        return i>0? RespMessUtil.build(CodeStatusEnum.SUCCESS,i):RespMessUtil.updateFailure();
    }

    @DeleteMapping("/deleteRoleByIDS")
    @ApiOperation("管理员批量删除角色")
    public RespMessUtil<Integer> delByIds(
            @ApiParam(name = "ids",value = "主键",required = true) @RequestParam("ids") List<Long> ids){

        Integer ids1 = brandService.deleteBatchByIds(ids);

        return ids1 > 0 ? RespMessUtil.build(CodeStatusEnum.SUCCESS, ids1) : RespMessUtil.deleteFailure();
    }


}
